package com.sun2.booksotong.dao.user;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.sun2.booksotong.model.user.Model4User;

public interface Dao4User {

	public static final String INSERT_USER = "INSERT INTO tbl_user(account, name, password) VALUES(#{account}, #{name}, #{password})";

	public static final String SELECT_USER_BY_NUM = "SELECT * FROM tbl_user WHERE user_id = #{num}";
	
	public static final String SELECT_USER_BY_ACCOUNT = "SELECT * FROM tbl_user WHERE account = #{account}";
	
	public static final String SELECT_USER_COUNT = "SELECT COUNT(*) FROM tbl_user";
	
	public static final String SELECT_USERS = "SELECT * FROM tbl_user ORDER BY num DESC LIMIT #{start_no}, #{row_count}";
	
	public static final String UPDATE_USER = "UPDATE tbl_user SET name = #{name}, password = #{password} WHERE num = #{num}";
	
	public static final String DELETE_USER = "DELETE FROM tbl_user WHETER num = #{num}";
	
	@Insert(INSERT_USER)
	public void createUser(Model4User model4User);
	
	@Select(SELECT_USER_BY_NUM)
	public Model4User readUserByNum(@Param("num") int num);
	
	@Select(SELECT_USER_BY_ACCOUNT)
	public Model4User readUserByAccount(@Param("account") String account);
	
	@Select(SELECT_USER_COUNT)
	public int readUserCount();
	
	@Select(SELECT_USERS)
	public Model4User[] readUsers(@Param("start_no") int start_no, @Param("row_count") int row_count);
	
	@Update(UPDATE_USER)
	public void updateUser(Model4User model4User);
	
	@Delete(DELETE_USER)
	public void deleteUser(@Param("num") int num);
	
}
